﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AutoMapper;
using Domain.Entity;
using Domain.Entity.zct;
using Domain.IRepository;

namespace Application.DepartmentService
{
    public class DepartmentService : IDepartmentService
    {
        private readonly IDepartmentRepository  departmentRepository;
        private readonly IMapper mapper;
        public DepartmentService(IDepartmentRepository departmentRepository, IMapper mapper)
        {
            this.departmentRepository = departmentRepository;
            this.mapper = mapper;
        }

        public async Task<int> AddDepartment(AddDepartmentDto addDepartmentDto)
        {
            Department department = mapper.Map<Department>(addDepartmentDto);
            return await departmentRepository.AddDepartment(department);
        }

        public async Task<int> DeleteDepartment(int id)
        {
            return await departmentRepository.DeleteDepartment(id);
        }

        //查询所有部门信息
        public async Task<List<Department>> GetDepartments()
        {
            return await departmentRepository.GetDepartments();
        }

        public async Task<FenYe<Department>> GetDepartmentsFenYe(FenYe<Department> fenYe, string? Department_code, string? Department_name, int? Department_status)
        {
            return await departmentRepository.GetDepartmentsFenYe(fenYe, Department_code, Department_name, Department_status);
        }

        public async Task<Department> GetDepartmentsID(int id)
        {
            return await departmentRepository.GetDepartmentsID(id);
        }

        public async Task<int> UpdateDepartments(UpdateDepartmentDto updateDepartmentsDto)
        {
            Department department = mapper.Map<Department>(updateDepartmentsDto);
            return await departmentRepository.UpdateDepartments(department);
        }
    }
}
